class Solution {
public:
    string minWindow(string s, string t) {
        int hashs[150]={0};
        int hasht[150]={0};
        int kinds=0;
        int minlen=INT_MAX;
        int begin=-100;
        for(auto ch:t)
        {
            if(hasht[ch]==0)
            {
                kinds++;
            }
            hasht[ch]++;
        }
        for(int left=0,right=0,count=0;right<s.size();++right)
        {
            hashs[s[right]]++;
            if(hashs[s[right]]==hasht[s[right]])
            {
                count++;
            }
            while(count==kinds)
            {
                if(right-left+1<minlen)
                {
                    minlen=right-left+1;
                    begin=left;
                }
                char out=s[left];
                left++;
                if(hashs[out]==hasht[out])
                {
                    count--;
                }
                hashs[out]--;
            }
        }
        if(begin==-100)
        {
            return "";
        }
        else
        {
            return s.substr(begin,minlen);
        }
    }
};
